Docker 101 - Containerizing our first application.
In this post we will learn what Docker is, how to use it, when it is appropiate to use it and we’ll make our first docker container based on a real-world production scenario.
- What is a container?
- What is Docker?
- What containers, and by extension Docker, are not.
- Installing Docker
- Running our very first container, and a look behind the scenes.
- Adding persistent storage.
- Networking.
- A hypothetical real-world production example
- Cleaning the images and temporary files we have created.
- Conclusions.
What is a container?
Containers can be conceptually thought of as an advanced version of chroot or a lighter alternative to virtualization.
A container is an isolated user-level instance of the OS. From the point of view of the applications running inside these instances the container behaves exactly like a real computer, and the application will have access only to the resources that are explicitly assigned to it.
Containers share the running kernel and general system calls of the host OS, which means that it is significantly less demanding than traditional virtualization resource-wise. The downside to this is that you can’t have an application running in a container with a different OS than the host.
Pros and cons of using containers.
Using containers has a few inmediate advantages:
-
We can package applications along with their dependencies, creating a portable version of the app and eliminating the dreaded “but it works on my machine“-scenario. This helps eliminate the proverbial walls between the Operations departament and Development’s.
-
It is significantly lighter than traditional OS virtualization, enabling a higher compute density in the same hardware.
-
Reduced the effort required to maintain the runtime environment, along with its complexity. Since the applications can be treated as an opaque self-contained bundle, the package and the behaviour are the same in testing and in production.
-
Since the infrastructure is declared as code, we benefit from the advantages of IaC: Infrastructure versioning, code as reliable documentation and straightforward deployment of new environments.
Of course, we must mention the disadvantages too:
-
Containers run on top of an additional abstraction layer compared to bare-metal.
-
Containers share the running kernel with the host. A bug/glitch in the running kernel affects all the running containers.
-
Container management is challenging, though tools like Docker Swarm and Google Kubernetes can mitigate this.
-
GUI applications don’t work well. While we can work around this using X11 forwarding, it’s not a straightforward solution.